<template>
  <div>
    <van-nav-bar title="不凡乐购" left-text="返回" left-arrow @click-left="onClickLeft" class="navbar" />
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-default="setdefault"
    />
  </div>
</template>

<script>
import areaList from "../../assets/js/area";
import { Toast } from "vant";
import { saveAction } from "@/api/home";
// import { deleteAction } from "@/api/nav";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      content: {},
    };
  },
  // created(){
  //   saveAction({

  //   })
  // },
  created() {
    // detailAction({
    //   id: this.$route.query.id
    // }).then(res => {
    //   console.log(res);
      // var reg = /.+?(省|市|自治区|自治州|县|区)/g;
      // var result = res.data.address.match(reg);
      // console.log(result);

      // this.addressInfo = res.data;
      // this.addressInfo.name = res.data.name;
      // this.addressInfo.tel = res.data.mobile;
      // this.addressInfo.addressDetail = res.data.address_detail;

      // this.addressInfo.province = result[0];
      // this.addressInfo.city = result[1];
      // this.addressInfo.county = result[2];
    // });
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSave(content) {
      console.log(content);
      this.content = content;
      // console.log(this.$route.query.id);
      saveAction({
        address:
          this.content.province + this.content.city + this.content.county,
        // addressId: this.$route.query.id? this.$route.query.id : '',
        checked: this.content.isDefault,
        detailadress: this.content.addressDetail,
        openId: 17516331686,
        telNumber: this.content.tel,
        userName: this.content.name
      }).then(res => {
        console.log(res);
      });
      Toast("保存地址成功");
      this.$router.push("/cart/address");
    },
    // onDelete(content) {
    //   console.log(content);
    //   deleteAction({
    //     id: this.$route.query.id
    //   }).then(res => {
    //     console.log(res);
    //   });
    //   this.addressInfo = {};
    //   if(content.areaCode =='' || content.areaCode == ''){
    //     Toast("您还未输入地址详情");
    //   }else{
    //     Toast("删除地址成功");
    //   }    
    // },
    setdefault(value){
      console.log(value);
    }
  }
};
</script>

<style lang="scss" scoped>
</style>